package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.view.View;

import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.ItemVoteUserBinding;
import com.jwdf.uda.ui.activity.UserInfoActivity;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.QuizDetailItem;
import com.jwdf.uda.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Administrator on 2016/9/7.
 */
public class QuizVoteUserViewHolder extends AbsViewHolder<QuizDetailItem>{
    private ItemVoteUserBinding mItemBinding;
    public QuizVoteUserViewHolder(View convertView) {
        super(convertView);
        mItemBinding = DataBindingUtil.bind(convertView);
        convertView.setOnClickListener(this);
    }

    @Override
    protected void onBindView(QuizDetailItem item) {
        PbBean.PbBaseVoterInfo vote = item.vote;
        if(vote == null) return;
        ImageLoader.getInstance().displayImage(vote.getVoterInfo().getAvatar().getUrl(), mItemBinding.ivHeader);
        mItemBinding.tvName.setText(StringUtils.filterNullAndTrim(vote.getVoterInfo().getNickname()));
        mItemBinding.setIsDesigner(vote.getVoterInfo().getIsDesigner());
        mItemBinding.tvIntroduction.setVisibility(TextUtils.isEmpty(StringUtils.filterNullAndTrim(vote.getVoterInfo().getIntroduction())) ? View.GONE:View.VISIBLE);
        mItemBinding.tvIntroduction.setText(vote.getVoterInfo().getIntroduction());
        PbBean.PbSignBaseVoteOptionType optionList=vote.getVoteOption();
        switch (optionList){
            case VOTE_OPTION_TYPE_A:
                mItemBinding.tvContent.setText(R.string.vote_plan_title_a);
                break;
            case VOTE_OPTION_TYPE_B:
                mItemBinding.tvContent.setText(R.string.vote_plan_title_b);
                break;
            case VOTE_OPTION_TYPE_C:
                mItemBinding.tvContent.setText(R.string.vote_plan_title_c);
                break;
            case VOTE_OPTION_TYPE_D:
                mItemBinding.tvContent.setText(R.string.vote_plan_title_d);
                break;
        }
    }
    @Override
    public void onClick(View v) {
        if(item.vote != null){
            UserInfoActivity.start(v.getContext(), item.vote.getVoterInfo().getUserId(), item.vote.getVoterInfo().getIsDesigner());
        }
    }
}
